using System;
using System.Collections.Generic;
using System.Text;

namespace Toenda.Foundation.Globalization {
	/// <summary>
	/// Implements the data object for the country
	/// </summary>
	public class CountryCode {
		private string _countryName;
		private string _isoTwo;
		private string _isoThree;
		private int _countryNumeric;
		private string _currency;
		private int _currencyNumeric;
		private string _currencyName;

		/// <summary>
		/// Creates a new instance of <see cref="CountryCode"/>
		/// </summary>
		public CountryCode() {
		}

		/// <summary>
		/// Creates a new instance of <see cref="CountryCode"/>
		/// </summary>
		/// <param name="countryName"></param>
		/// <param name="isoTwo"></param>
		/// <param name="isoThree"></param>
		/// <param name="countryNumber"></param>
		/// <param name="currency"></param>
		/// <param name="currencyNumber"></param>
		/// <param name="currencyName"></param>
		public CountryCode(
			string countryName, string isoTwo, string isoThree, int countryNumber, 
			string currency, int currencyNumber, string currencyName
		) {
			this._countryName = countryName;
			this._isoTwo = isoTwo;
			this._isoThree = isoThree;
			this._countryNumeric = countryNumber;
			this._currency = currency;
			this._currencyNumeric = currencyNumber;
			this._currencyName = currencyName;
		}

		/// <summary>
		/// Get or set the name of the country
		/// </summary>
		public string CountryName {
			get {
				this.InitializeOnRequest(this._countryName);
				return this._countryName;
			}
			set { this._countryName = value; }
		}

		/// <summary>
		/// Get or set the two letter ISO name
		/// </summary>
		public string TwoLetterISOLanguageName {
			get {
				this.InitializeOnRequest(this._isoTwo);
				return this._isoTwo;
			}
			set { this._isoTwo = value; }
		}

		/// <summary>
		/// Get or set the three letter ISO name
		/// </summary>
		public string ThreeLetterISOLanguageName {
			get {
				this.InitializeOnRequest(this._isoThree);
				return this._isoThree;
			}
			set { this._isoThree = value; }
		}

		/// <summary>
		/// Get or set the number of the country
		/// </summary>
		public int CountryNumber {
			get { return this._countryNumeric; }
			set { this._countryNumeric = value; }
		}

		/// <summary>
		/// Get or set the currency
		/// </summary>
		public string Currency {
			get {
				this.InitializeOnRequest(this._currency);
				return this._currency;
			}
			set { this._currency = value; }
		}

		/// <summary>
		/// Get or set the currency number
		/// </summary>
		public int CurrencyNumber {
			get { return this._currencyNumeric; }
			set { this._currencyNumeric = value; }
		}

		/// <summary>
		/// Get or set the name of the currency
		/// </summary>
		public string CurrencyName {
			get {
				this.InitializeOnRequest(this._currencyName);
				return this._currencyName;
			}
			set { this._currencyName = value; }
		}

		/// <summary>
		/// Initializes this object, if it isnt yet. Maybe this has to, 
		/// if the object is created manually without loading by the provider
		/// </summary>
		/// <param name="field"></param>
		private void InitializeOnRequest(string field) {
			if(field is string && field.IsNullOrTrimmedEmpty()) {
				//CountryCodeProvider prov = new CountryCodeProvider();
				//CountryCode tmp = null;

				//if(!this._isoTwo.IsNullOrTrimmedEmpty()) {
				//    tmp = prov.GetCountryCode(this._isoTwo);
				//}
				//else if(!this._isoThree.IsNullOrTrimmedEmpty()) {
				//    tmp = prov.GetCountryCode(this._isoThree);
				//}

				//if(tmp != null) {
				//    this._countryName = tmp.CountryName;
				//    this._isoTwo = tmp.TwoLetterISOLanguageName;
				//    this._isoThree = tmp.ThreeLetterISOLanguageName;
				//    this._countryNumeric = tmp.CountryNumber;
				//    this._currency = tmp.Currency;
				//    this._currencyNumeric = tmp.CurrencyNumber;
				//    this._currencyName = tmp.CurrencyName;
				//}
			}
		}
	}
}
